<?php
class EditpwdAction extends CommonAction {
    public function index(){
		$this->display();
    }
	
	public function edit(){
		$oldpassword = I('oldpassword', '', 'trim');
		$password = I('password', '', 'trim');
		$newpassword = I('newpassword', '', 'trim');
		
		if(setPassword($oldpassword, $this->adminInfo['pwd_salt']) != $this->adminInfo['password']){
			$this->error('原始密码不正确!');	
		}
		
		if(empty($password) || empty($newpassword) || $password != $newpassword){
			$this->error('两次输入的密码不一致!');		
		}
		
		if($oldpassword == $newpassword){
			$this->error('新密码不能和原始密码一致!');		
		}
		
		if(D('Admin')->changePassword($this->adminInfo['id'],setPassword($password, $this->adminInfo['pwd_salt']))){
			$this->success('密码修改成功,请重新登录!',U('Login/logout'));	
		}else{
			$this->error('密码修改失败!');		
		}
		
	}
}